<template>
    <div>
        <h1>商铺添加</h1>
        <table class="table">
            <tr>
                <td>商铺名称</td>
                <td><input type="text" v-model="data.rname"></td>
            </tr>
            <tr>
                <td>联系人手机号</td>
                <td><input type="text" v-model="data.rphone"></td>
            </tr>
            <tr>
                <td>商铺楼层</td>
                <td>
                <select v-model="data.rlc">
                    <option value="">请选择</option>
                    <option value="1层">1层</option>
                    <option value="2层">2层</option>
                    <option value="3层">3层</option>
                    <option value="4层">4层</option>
                </select>
                </td>
            </tr>
            <tr>
                <td>商铺编号</td>
                <td><input type="text" v-model="data.rbh"></td>
            </tr>
            <tr>
                <td>建筑面积</td>
                <td><input type="text" v-model="data.rjzmj"></td>
            </tr>
            <tr>
                <td>室内面积</td>
                <td><input type="text" v-model="data.rsnmj"></td>
            </tr>
            <tr>
                <td>租金(元/平方)</td>
                <td><input type="text" v-model="data.rzj"></td>
            </tr>
            <tr>
                <td>商品状态</td>
                <td><select v-model="data.typeId">
                    <option value="0">请选择</option>
                    <option v-for="x in xl" :value="x.typeId">{{x.tname}}</option>
                </select></td>
            </tr>
            <tr>
                <td>备注说明</td>
                <td><textarea v-model="data.rbz"></textarea></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="新增" @click="add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter} from 'vue-router'
const router=useRouter();
const data=ref({
    "rid": 0,
  "rname": "",
  "rphone": "",
  "rlc": "",
  "rbh": "",
  "rjzmj": "",
  "rsnmj": "",
  "rzj": 0,
  "typeId": 0,
  "rbz": ""
})
const add=()=>{
    axios.post("/api/Room/AddRoom",data.value).then(res=>{
        if(res.data==-1){
            alert("联系人手机号不能一样")
            return
        }
        else if(res.data>0){
            alert("新增成功")
            router.push({path:"/"})
        }
        else{
            alert("新增失败")
            return
        }
    })
}
onMounted(()=>{
    xlk()
})
const xl=ref([{
    "typeId": 0,
    "tname": ""
}])
const xlk=()=>{
    axios.get("/api/Room/GetTypeList").then(res=>{
        xl.value=res.data
    })
}
</script>

<style scoped>

</style>